package com.fz.study.project.controller;


import com.fz.study.project.entity.Course;
import com.fz.study.project.entity.Result;
import com.fz.study.project.entity.qurey.CourseQuery;
import com.fz.study.project.service.ICourseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程信息 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-02-17
 */
@Tag(name = "课程信息")
@RestController
@RequiredArgsConstructor
@RequestMapping("/course")
public class CourseController {

    private final ICourseService courseService;

    @Operation(summary = "添加课程")
    @PutMapping("/add")
    public Result add(@RequestBody Course course){
        courseService.saveByName(course);
        return Result.success("添加成功！");
    }

    @Operation(summary = "删除与批量删除")
    @DeleteMapping("{ids}")
    public Result remove(@PathVariable List<Integer> ids){
        courseService.removeWithIds(ids);
        return Result.success("删除成功！");
    }

    @Operation(summary = "修改")
    @PutMapping("/update")
    public Result updateById(@RequestBody Course course){
        courseService.updateWithId(course);
        return Result.success("修改用户成功！");
    }

    @Operation(summary = "遍历用户信息")
    @GetMapping("list")
    public Result list(){
        List<Course> list = courseService.list();
        return Result.success(list);
    }

    @Operation(summary = "分页查询")
    @PostMapping("/page")
    public Result page(@RequestBody CourseQuery query){
        return Result.success(courseService.findByPage(query));
    }

}
